﻿using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;

namespace Poi.NET.poifs.storage
{
/**
 * A list of RawDataBlocks instances, and methods to manage the list
 *
 * @author Marc Johnson (adapted by Josh Fornwall)
 */

public class RawDataBlockList : BlockListImpl
{

    /**
     * Constructor RawDataBlockList
     *
     * @param stream the InputStream from which the data will be read
     * @param bigBlockSize The big block size, either 512 bytes or 4096 bytes
     *
     * @exception IOException on I/O errors, and if an incomplete
     *            block is read
     */

    public RawDataBlockList(StreamReader stream, int bigBlockSize)
    {
        List<RawDataBlock> blocks = new List<RawDataBlock>();

        while (true)
        {
            RawDataBlock block = new RawDataBlock(stream, bigBlockSize);
            
            // If there was data, add the block to the list
            if(block.hasData()) {
            	blocks.Add(block);
            }

            // If the stream is now at the End Of File, we're done
            if (block.eof()) {
                break;
            }
        }
        setBlocks(( RawDataBlock [] ) blocks.ToArray());
    }
}   // end public class RawDataBlockList

}
